#pragma comment(lib, "freeglut.lib")
#pragma comment(lib, "opengl32.lib")

#include <iostream>
#include <gl/freeglut.h>

using namespace std;

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

unsigned char lastChar = 'n';
int startTicks = 0;
int pausedTicks = 0;
bool running;

void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glBegin(GL_TRIANGLES);
		glVertex3f(-0.5,-0.5,0.0);
		glVertex3f(0.5,0.0,0.0);
		glVertex3f(0.0,0.5,0.0);
	glEnd();

	glutSwapBuffers();
}

void reshape(int w, int h)
{
	if (h == 0)
		h = 1;
	double ratio = 1.0 * w / h;
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glViewport(0, 0, w, h);
	gluPerspective(45, (float)ratio, 1, 1000);
	glMatrixMode(GL_MODELVIEW);
}

void keyboard (unsigned char c, int x, int y)
{
	switch(c)
	{
		case 'W':
		case 'w':
			cout << "The last character pressed was: " << lastChar << endl;
			cout << c << " was pressed" << endl;
			lastChar = c;
			break;
		case 'A':
		case 'a':
			cout << "The last character pressed was: " << lastChar << endl;
			cout << c << " was pressed" << endl;
			lastChar = c;
			break;
		case 'S':
		case 's':
			cout << "The last character pressed was: " << lastChar << endl;
			cout << c << " was pressed" << endl;
			lastChar = c;
			break;
		case 'D':
		case 'd':
			cout << "The last character pressed was: " << lastChar << endl;
			cout << c << " was pressed" << endl;
			lastChar = c;
			break;
		case '\033':
			running = false;
			exit(0);
			break;
	}
}

int main( int argc, char* argv[])
{
	running = true;
	cout << "Initializing OpenGL..." << endl;
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
 
    glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("Main Window");
 
	cout << "OpenGL successfully initialized" << endl;

	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
 
	glutMainLoop();

	return 0;
}